// 初始渲染首页搜索到的商品
var search_goods = localStorage.getItem('search_goods');
var goods_arr = JSON.parse(search_goods)
if (goods_arr != null) {
    var search_goods_str = ``
    goods_arr.forEach((obj) => {
        search_goods_str += `<li>
            <div class="recommend-goods-pic">
                <img src="${obj.img}" alt="">
            </div>
            <p class="more2_info_name">
                <i class="more2_info_self">${obj.saleMol}</i>${obj.name}</p>
            <span class="mod_price"><i>¥</i>
            ${obj.price}</span>
            <span class="more2_discount">${obj.saleAct}</span>
            </li>`
    });
    $('.recommend-goods ul').html(search_goods_str);
    remove()
}

function remove() {
    $('.more2_info_self').each((i, val) => {
        if ($(val).text() == '') {
            $(val).remove()
        }
    })
    $('.more2_discount').each((j, val) => {
        if ($(val).text() == '') {
            $(val).remove()
        }
    })
}
// 搜索渲染商品
function searchGoods() {
    localStorage.removeItem('search_goods')
    let keyword = $('.form input').val()
    let searchStr = ``
    modules.forEach((obj) => {
        obj.goods.forEach((every) => {
            if (every.goodsList[0].name.includes(keyword)) {
                searchStr += `<li>
                <div class="recommend-goods-pic">
                    <img src="${every.goodsList[0].img}" alt="">
                </div>
                <p class="more2_info_name">
                    <i class="more2_info_self">${every.goodsList[0].saleMol}</i>${every.goodsList[0].name}</p>
                <span class="mod_price"><i>¥</i>
                ${every.goodsList[0].price}</span>
                <span class="more2_discount">${every.goodsList[0].saleAct}</span>
            </li>`
            }
        })
    })
    $('.recommend-goods ul').html(searchStr);
    remove();
    $('.form input').val('')
}

$('.form input')[0].onkeyup = function (e) {
    if (e.keyCode == 13) {
        searchGoods()
    }
}
$('.icon-fangdajing').click(function () {
    searchGoods()
})
$('.menu').mouseover(function () {
    $('.main-content').show();
    $('.sort a:first-of-type').css('border-bottom', '3px solid #f30213')
})
$('.main-content').mouseleave(function () {
    $(this).hide()
    $('.sort a:first-of-type').css('border-bottom', 'none')
})